package cc.autoapi.pucong.auto.flow.persistence.utils.jdbc;

import java.io.Serializable;
import java.util.List;

public class BasePageVo<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public BasePageVo(Integer pageSize, Integer pageNum) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
    }

    private Integer pageSize;

    private Integer pageNum;
    // 总页数
    private Integer pages;

    private List<T> records;

    private Long total;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public long offset() {
        return getPageNum() > 0 ? (getPageNum() - 1) * getPageSize() : 0;
    }

    public long runPages() {
        if (getPageSize() == 0) {
            return 0L;
        }
        long pages = getTotal() / getPageSize();
        if (getTotal() % getPageSize() != 0) {
            pages++;
        }
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }

    public Integer getPages() {
        return pages;
    }
}
